# Maintainer: Andreas 'Segaja' Schleifer <archlinux at segaja dot de>
# Contributor: Mario Finelli <mario at finel dot li>

_gemname='docile'
pkgname="ruby-${_gemname}"
pkgver=1.4.0
pkgrel=3
pkgdesc="keeps your Ruby DSLs tame and well-behaved"
arch=('any')
url='https://ms-ati.github.io/docile'
license=('MIT')
depends=('ruby')
checkdepends=('ruby-rake' 'ruby-rspec' 'ruby-simplecov')
options=(!emptydirs)
source=("https://github.com/ms-ati/docile/archive/v$pkgver/$_gemname-$pkgver.tar.gz")
sha512sums=('78350144a9b0d84d6025770d05b1e9999f34ce431691c08e73232f8b10537bc265f9f06409ff6feabf2e6f20d018dbb83aaf8c0f66e7dcec3e195475820481cd')

prepare() {
  cd "${_gemname}-${pkgver}"

  # we use an archive not a git checkout
  sed --in-place --regexp-extended 's|git ls-files -z|find -print0|' "${_gemname}.gemspec"
}

build() {
  cd "${_gemname}-${pkgver}"

  gem build "${_gemname}.gemspec"
}

check() {
  cd "${_gemname}-${pkgver}"

  rake spec
}

package() {
  cd "${_gemname}-${pkgver}"

  local _gemdir="$(gem env gemdir)"

  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "${pkgdir}/${_gemdir}" \
    --bindir "${pkgdir}/usr/bin" \
    "${_gemname}-${pkgver}.gem"

  # remove unrepreducible files
  rm --force --recursive --verbose \
    "${pkgdir}/${_gemdir}/cache/" \
    "${pkgdir}/${_gemdir}/gems/${_gemname}-${pkgver}/vendor/" \
    "${pkgdir}/${_gemdir}/doc/${_gemname}-${pkgver}/ri/ext/"

  find "${pkgdir}/${_gemdir}/gems/" \
    -type f \
    \( \
      -iname "*.o" -o \
      -iname "*.c" -o \
      -iname "*.so" -o \
      -iname "*.time" -o \
      -iname "gem.build_complete" -o \
      -iname "Makefile" \
    \) \
    -delete

  find "${pkgdir}/${_gemdir}/extensions/" \
    -type f \
    \( \
      -iname "mkmf.log" -o \
      -iname "gem_make.out" \
    \) \
    -delete

  install --verbose -D --mode=0644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
  install --verbose -D --mode=0644 *.md --target-directory "${pkgdir}/usr/share/doc/${pkgname}"
}

# vim: set ts=2 sw=2 et:
